$(function() {
  'use strict';
  $('#exampleModal').on('show.bs.modal', function (event) {

  })

  $('#create-bt').on('click', function (event) {
    $.ajax({
      type: "get",
      dataType: "json",
      url: "/site/create/"+$("#site_name").val(),
      success: function (result) {
        if (result.code == 0) {
          $("#site_list").append("<p>"+result.data.name+"，时间："+result.data.created_time+"，<a href=\"/site/dir/"+result.data.md5+"\">查看站点目录</a></p>");
          $("#site_name").val("")
          $("#exampleModal").modal('hide')
        } else {
          alert(result.msg);
        }
      },
      error : function() {
        alert("异常！");
      }
    });
    return false;
  })

  $('div.split-pane').splitPane();
  $('#close_left_bar').on('click', function() {
    if ($(this).attr('data-flag') == 'on') {
      $(".left-bar").hide();
      $(this).html('<span class="glyphicon glyphicon-list" aria-hidden="true" title="展开菜单"></span>');
      $(this).attr('data-flag','off');
      $('div.split-pane').splitPane('firstComponentSize', 40);
    } else {
      $(".left-bar").show();
      $(this).html('<span class="glyphicon glyphicon-align-justify" aria-hidden="true"></span> 折叠菜单');
      $(this).attr('data-flag','on');
      $('div.split-pane').splitPane('firstComponentSize', 200);
    }
  });

  $(".zip").bind('click', function(){
    $.ajax({
        type: "GET",
        dataType: "json",
        url: "/"+$(this).attr("data-siteid")+"/deploy/zip",
        success: function (result) {
            if (result.code == 0) {
                bootoast({
                    message: '打包成功',
                    type: 'success',
                    position:'right-bottom',
                    timeout:2
                });
            } else {
                bootoast({
                    message: '打包失败，'+result.msg,
                    type: 'warning',
                    position:'right-bottom',
                    timeout:2
                });
            }
        },
        error : function() {
            bootoast({
                message: '异常',
                type: 'danger',
                position:'right-bottom',
                timeout:2
            });
        }
    });
  });
  //ftp发布压缩包
  $(".deploy").bind('click', function(){
    $.ajax({
      type: "POST",
      dataType: "json",
      url: "/"+$(this).attr("data-siteid")+"/deploy/ftp",
      data:{path:$(this).attr("data-path")},
      success: function (result) {
        if (result.code == 0) {
          bootoast({
            message: '发布任务已发出，请稍候查看结果',
            type: 'success',
            position:'right-bottom',
            timeout:2
          });
        } else {
          bootoast({
            message: '任务发起失败，'+result.msg,
            type: 'warning',
            position:'right-bottom',
            timeout:2
          });
        }
      },
      error : function() {
        bootoast({
          message: '异常',
          type: 'danger',
          position:'right-bottom',
          timeout:2
        });
      }
    });
  });
});
